﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web.Mvc;
using System.Web.UI;

using ProjectBase.Core;
using ProjectBase.Core.Web;
using $safeprojectname$;

namespace $safeprojectname$
{
    public class TreeViewNode : TreeView, IMasterPageLessView
    {
        protected override void BuildControls()
        {
            ProcessExpanded();
            Controls.Add(CreateChildren(Model.CurrentItem.Items));
        }

        #region IView Members

        public void Render(ViewContext viewContext, TextWriter writer)
        {
            ViewContext = viewContext;
            ManageState(viewContext); // init

            BuildControls(); // create control tree

            RenderControl(new HtmlTextWriter(writer)); // render control tree
        }

        #endregion

        #region State
        protected virtual void ProcessExpanded()
        {
            var expanded = ExpandedNodes;

            if (expanded.Contains(Model.NodeID)) // existing must be removed
            {
                expanded.Remove(Model.NodeID);
                return;
            }
            expanded.Add(Model.NodeID); // newly opened must be added
        }
        #endregion State
    }
}